草庐IT

Android Test测试前提条件

全部标签

testing - 您如何构建用于在项目模块内进行测试的导入?

我试图了解如何将一个go项目构建为子模块,这些子模块存储在单独的源代码存储库中(在主机example.com上),但是当我这样做时,我不确定如何运行模块内的测试。以下示例中哪里出了问题,非常感谢您的帮助!!mkdir-psrc/example.com/john/toolecho"packagetool">>src/example.com/john/tool/book.goecho"">>src/example.com/john/tool/book.goecho"typeBookstruct{">>src/example.com/john/tool/book.goecho"Titlest

go - Redigo:在 Apache 负载测试中出现错误

我正在使用库redigo将我的go程序连接到redis。当我运行一个请求时,我得到了正确的结果。但是在负载测试中,使用apache基准测试工具,它在以下情况下起作用:ab-n1000-k-c10-ppost.txt-Tapplication/x-www-form-urlencodedhttp://localhost:8084/abcd但是当请求是:ab-n1000-k-c15-ppost.txt-Tapplication/x-www-form-urlencodedhttp://localhost:8084/abcd我收到错误:panic:dialtcp:6379:toomanyopen

unit-testing - 在 golang 中重置 http 处理程序以进行单元测试

我正在golang中测试一个http服务器,除了一件烦人的事情外,一切看起来都很顺利。在某些时候,当我配置服务器时,在执行http.ListenAndServe之前,我使用http.Handle("/",myrouter)注册了一个处理程序,问题是在下面的测试中,当再次调用配置方法时,我收到以下panic:panic:http:multipleregistrationsfor/[recovered]我想在干净的环境中运行每个测试,但还没有找到拆除http.DefaultServeMux的方法,有没有一种方便的方法可以通过“无效”来做到这一点或者重新配置测试环境,以便每个测试都在新环境中

golang gorilla/mux 和测试,在哪里存储路由

在我看过的大多数文档中,gorillamux都被建议像这样使用...funcmain(){m:=mux.Router()m.HandleFunc("/",FuncNameOrDef)http.ListenAndServe(":8080",m)}这很好,但它给我留下了一个问题,因为据我所知,为了测试,我需要重新声明mux和路由,除非我在像这样的函数之外声明mux和路由。.var(m=mux.Router()_=m.HandleFunc("/",FuncNameOrDef))然后在我的测试中这样做...funcTestSomeView(t*testing.T){ts:=httptest.N

json - Golang Godog REST API 测试失败

在过去的2周里,我一直在研究GODOG,这是一个类似于golang的bdd的cucumber。我发现它非常有趣,最近我花更多时间为我的RESTAPI编写测试。最近,我一直在努力通过我的一项考试。这一个包含一个JSON结构,该结构本身内部有子JSON。此外,我正在按照以下链接找到的确切示例进行测试:https://github.com/DATA-DOG/godog/tree/master/examples/api我有一个像这样的结构:typeStatusstruct{ErrorCodestring`json:"ERROR_CODE"`ErrorTextstring`json:"ERROR

go - 如果条件在 golang 模板中的范围内嵌套

如何在go的范围迭代循环中使用if条件?packagemainimport"os"import"text/template"constt=`{{range$i,$v:=.}}{{$i}}{{$v}}{{if$igt0}},{{end}}{{end}}`funcmain(){d:=[]string{"a","b","c"}template.Must(template.New("").Parse(t)).Execute(os.Stdout,d)}https://play.golang.org/p/IeenD90FRM 最佳答案 如果你c

unit-testing - 仅测试文件中的掩码包名称

为了追求100%的单元测试覆盖率,我们尝试在一个函数中测试多行代码。相关函数调用运行时包://functionNamereturnsastringrepresentingthefunctionnameofthefunctionnstackframesabovethecaller.//ifn=0,thenameofthefunctioncallingfunctionName()willbereturned.funcfunctionName(nint)string{pc,_,_,ok:=runtime.Caller(n+1)if!ok{return"unknownfunction"}me:

unit-testing - 在 Go 中进行单元测试时,是否可以动态断言两个值是否相等?

我刚刚开始使用Go。我正在编写单元测试,我希望能够使用表格进行测试,其中要与实际结果进行比较的结果有时应该或不应该相等。例如,这是我目前拥有的代码:packagemainimport("github.com/stretchr/testify/assert""testing")funcTestFunc(t*testing.T){tables:=[]struct{inputstringcomparisonResultstringshouldBeEqualbool}{{"someirrelevantinput","someresult",true,},{"someotherirrelevan

validation - 如何在 golang 中使用 ozzo 验证执行条件所需的验证?

在Golangozzo-validation中,如何验证依赖于另一个字段的字段?例如,如果我有以下内容:returnvalidation.ValidateStruct(&c,validation.Field(&c.Name,validation.Required,validation.Length(5,20)),validation.Field(&c.Gender,validation.In("Female","Male")),validation.Field(&c.Email,is.Email),validation.Field(&c.Address),如何添加验证以确保仅当电子邮件

unit-testing - 如何模拟/单元测试嵌套函数

我有一个函数在其他函数中被调用。send_api.gofunction*send_api*(client*http.Client,urlstring)map[string]string,error{//sendapirequestandparsetheresponseandreturnthedictreturndictmapforeg:{applefruit}}然后这个函数在ma​​in()函数中被调用func*main()*{getmap:=send_api(client*http.Client,"test.com")}good.gofunc*get_dict_key*(keystr